package com.yc.service;

import com.google.protobuf.ByteString;
import com.yc.grpc.client.GrpcCommonRequest;
import com.yc.grpc.client.GrpcCommonResponse;
import com.yc.grpc.service.CommonRequest;
import com.yc.grpc.service.CommonResponse;
import com.yc.grpc.service.GrpcCommonServiceGrpc;
import com.yc.util.FurySerializeUtils;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;

import java.nio.charset.StandardCharsets;

/**
 * @Author: ZhouJianLong
 * @Date: 2024/07/22/14:04
 * @Description:
 */
@GrpcService
public class GrpcCommonServiceImpl extends GrpcCommonServiceGrpc.GrpcCommonServiceImplBase {
    @Override
    public void commonHandle(CommonRequest request, StreamObserver<CommonResponse> responseObserver) {
        GrpcCommonRequest deserialize = FurySerializeUtils.deserialize(request);
        GrpcCommonResponse grpcCommonResponse = new GrpcCommonResponse();
        grpcCommonResponse.setResult(deserialize.getBeanName()+"#"+deserialize.getMethod());
        grpcCommonResponse.setStatus(200);
        ByteString serialize = FurySerializeUtils.serialize(grpcCommonResponse);
        responseObserver.onNext(CommonResponse.newBuilder().setResponse(
                serialize
                ).build());
        responseObserver.onCompleted();
    }
}
